#include<bits/stdc++.h>
using namespace std;

struct Node{
	int state;
	string step;
	Node(){}
	Node(int state){
		this->state=state;
	}
	bool operator <(const Node& node) const{
		if(step.length()>node.step.length()) return true;
		if(step.length()<node.step.length()) return false;
		for(int i=0;step[i]!='\0';i++){
			if(step[i]>node.step[i]) return true;
			if(step[i]>node.step[i]) return false;
		}
		return true;
	}
	bool operator==(const Node& node) const{
		return state==node.state&&step==node.step;
	}
	bool operator!=(const Node& node) const{
		return !(state==node.state&&step==node.step);
	}
};
unordered_map<int,Node> ump[2];

string moves[]={
	"abde","abc","bcef",
	"adg","bdefh","cfi",
	"degh","ghi","efhi" 
};
const int op[2]={1,-1};
int main(){
	int s0=0;
	for(int i=0;i<9;i++){
		s0*=4;
		int u;
		scanf("%d",&u);
		u=u/3%4;
		s0+=u;
	}
	Node node0,nodet;
	node0.state=s0;
	ump[0][s0]=node0;
	nodet.state=0;
	ump[1][0]=nodet;
	priority_queue<Node> que[2];
	que[0].push(node0);
	ump[0][s0]=node0;
	que[1].push(nodet);
	ump[1][0]=nodet;

	if(s0==0){
		return 0;
	}
	int tag=0;
	while(!que[tag].empty()){
		int tag_=(tag==0?1:0);
		int size=que[tag].size();
		for(int i=0;i<size;i++){
			Node node=que[tag].top();
			que[tag].pop();
			int state0=node.state;
			string step0=node.step;
			if(node!=ump[tag][state0]){
				continue;
			}
			int s[9];
			for(int k=8;k>=0;k--){
				s[k]=state0%4;
				state0/=4;
			}
			for(int j=0;j<9;j++){
				int sj[9];
				for(int u=0;u<9;u++){
					sj[u]=s[u];
				}
				for(auto c:moves[j]){
					sj[c-'a']=(s[c-'a']+op[tag]+4)%4;
				}
				int staten=0;
				for(int u=0;u<9;u++){
					staten*=4;
					staten+=sj[u];
				}
				Node noden;
				string stepn;
				//stepn-> head add or tail add
				if(tag==0){
					stepn=step0+(char)(j+'1');
				}
				else{
					stepn=(char)(j+'1')+step0;
				}
				noden.step=stepn;
				noden.state=staten;
				//查重
				if(ump[tag].count(staten)){
					if(ump[tag][staten]<noden){
						ump[tag][staten]=noden;
					}
				}
				else{
					ump[tag][staten]=noden;
				}
				//找到另一端
				if(ump[tag_].count(staten)){
					//当前是正向
					if(tag==0){
						for(auto c:stepn){
							cout<<c<<' ';
						}
						string str_tail=ump[tag_][staten].step;
						for(auto c:str_tail){
							cout<<c<<' ';
						}
						return 0;
					}
					//当前是反向
					if(tag==1){
						string str_head=ump[tag_][staten].step;
						for(auto c:str_head){
							cout<<c<<' ';
						}
						for(auto c:stepn){
							cout<<c<<' ';
						}
						return 0;
					}
				}
				//
				que[tag].push(noden);
			}
		}
		tag=tag_;
	}
	return 0;
}
